<!--
 * @Description: 创建班级用户奖励排行
 * @Author: liyujie
 * @Date: 2021/07/26
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/07/26
-->
<template>
    <section class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <div class="header-title">
                    用户奖励排行
                </div>
                <div
                    class="back"
                    @click="handleRoute('createClass')"
                >返回</div>
            </div>
            <!-- /header -->
            <!-- 筛选-->
            <div class="filter-view">
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        创建用户信息
                    </p>
                    <el-input
                        placeholder="请输入用户编号/手机号"
                        v-model="filterData.keyword"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 260px"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        学校名称
                    </p>
                    <el-cascader
                        v-model="filterData.school_name"
                        placeholder="请选择学校"
                        :options="school_tree"
                        filterable
                        clearable
                        size="medium"
                        expand-trigger="click"
                        style="width: 260px"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                        :props="{
                            label: 'name',
                            value: 'name',
                            children: 'children',
                            emitPath: false
                        }"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        学院名称
                    </p>
                    <el-input
                        placeholder="请输入学院名称"
                        v-model="filterData.college_name"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 260px"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        专业名称
                    </p>
                    <el-input
                        placeholder="请输入专业名称"
                        v-model="filterData.major_name"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 260px"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        班级名称
                    </p>
                    <el-input
                        placeholder="请输入班级名称"
                        v-model="filterData.class_name"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 260px"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        校园精英等级
                    </p>
                    <el-select
                        placeholder="全部"
                        v-model="filterData.agent_level"
                        size="medium"
                        style="width: 152px"
                        @change="getTableData(1)"
                    >
                        <el-option
                            label="全部"
                            :value="99"
                        />
                        <el-option
                            v-for="item in 6"
                            :key="item"
                            :label="`E${item - 1}`"
                            :value="item - 1"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        class="query-button"
                        @click="getTableData(1)"
                    >
                        查询
                    </el-button>
                    <el-button
                        type="text"
                        @click="handleReset()"
                    >
                        重置
                    </el-button>
                </div>
            </div>
            <!--筛选-->
            <!-- table -->
            <div class="table-wrapper">
                <el-table
                    :data="tableData"
                    height="100%"
                    style="width: 100%;"
                    ref="table"
                    class="data-table"
                    :cell-style="{height: '40px'}"
                    v-loading="tableLoading"
                    @sort-change="handleSortChange"
                >
                    <el-table-column
                        label="序号"
                        align="center"
                        width="60"
                        type="index"
                        fixed="left"
                    />
                    <el-table-column
                        label="创建用户信息"
                        width="200"
                        fixed="left"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <div class="cell-title">{{ scope.row.true_name ? scope.row.true_name : '--' }}</div>
                            <div class="cell-tips">手机号：{{ scope.row.phone }}</div>
                            <div class="cell-tips">用户ID：{{ scope.row.student_no }}</div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="精英等级"
                        align="center"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            E{{ scope.row.agent_level }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="school_name"
                        label="学校信息"
                        width="140"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        prop="college_name"
                        label="学院信息"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        prop="major_name"
                        label="专业信息"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        prop="enter_school_year"
                        label="入学年份"
                        align="center"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        prop="class_name"
                        label="班级信息"
                        align="center"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        prop="class_group_number"
                        label="班级群号"
                        align="center"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        prop="total_award_money"
                        label="合计奖励"
                        align="center"
                        :formatter="emptyFormatter"
                        sortable="custom"
                    />
                    <el-table-column
                        label="操作"
                        align="left"
                        fixed="right"
                        width="180"
                    >
                        <template slot-scope="scope">
                            <div class="option-btn-group">
                                <el-button
                                    type="text"
                                    size="medium"
                                    @click="$refs.awardRankDetailDialog.show(scope.row.student_no)"
                                >
                                    查看详情
                                </el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <!-- /table -->
            <!-- /分页 -->
            <div class="pagination-wrapper clearfix">
                <el-pagination
                    layout="total, prev, pager, next, jumper"
                    background
                    :current-page.sync="page.now_page"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />
            </div>
        </div>
        <!--查看详情弹窗-->
        <award-rank-detail-dialog
            ref="awardRankDetailDialog"
        />
    </section>
</template>

<script>
import { back } from '@/mixin/back';
import AwardRankDetailDialog from "@/components/create-class/award-rank-detail-dialog";

export default {
    name: 'CreateClassRank',
    mixins: [back],
    components: {AwardRankDetailDialog},
    data() {
        return {
            filterData: {
                // 用户真实姓名/手机/ID
                keyword: '',
                // 学校名称
                school_name: '',
                // 学院名称
                college_name: '',
                // 专业名称
                major_name: '',
                // 班级名称
                class_name: '',
                // 精英等级
                agent_level: 99,
                sort_field: '',
                sort_type: '',
            },
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            school_tree: [],
            authResult: {}
        };
    },
    computed: {},
    filters: {},
    watch: {},
    mounted() {
        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '社交'}, {title: '班级管理'}, {
            title: '创建同校班级',
            path: '/student/create-class'
        }, {title: '用户奖励排行'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
        this.getSchoolTree();
    },

    methods: {

        /**
         * @description 获取省/市/学校三级联动
         */
        getSchoolTree () {
            this.$post('/student/local_info%5Cschool_tree',{},resp => {
                if (resp.code === 1) {
                    this.school_tree = resp.data.tree;
                }
            });
        },

        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {
            this.tableLoading = true;
            let params = { ...this.filterData };

            params.page_id = page || this.page.now_page;
            this.$post('/student/task_stuagent_extra_class_create%5Cget_user_award_ranking_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                    this.page = res.data.page;
                } else {
                    this.$notify({
                        title: '提示',
                        message: res.msg,
                        type: 'warning'
                    });
                }
                this.tableLoading = false;
            });
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },

        /**
         * 重置筛选条件
         */
        handleReset() {
            this.filterData = {
                keyword: '',
                school_name: '',
                college_name: '',
                major_name: '',
                class_name: '',
                agent_level: 99,
                sort_field: '',
                sort_type: ''
            };
            this.$refs.table.clearSort();
            this.getTableData(1);
        },

        /**
         * 处理排序
         * @param data
         */
        handleSortChange(data) {
            console.log(data);

            let sortTypeMap = {
                ascending: 0,
                descending: 1
            };

            if (data.order) {
                this.filterData.sort_field = data.prop;
                this.filterData.sort_type = sortTypeMap[data.order];
            } else {
                this.filterData.sort_field = '';
                this.filterData.sort_type = '';
            }

            this.getTableData();
        },
    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        background: #fff;
        box-sizing: border-box;

        /*header*/

        .header {
            height: 68px;
            padding: 24px;
            box-sizing: border-box;
            box-shadow: 0px -1px 0px 0px #F0F2F5;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid #F0F2F5;

            .header-title {
                color: #333333;
                font-size: 20px;
                height: 20px;
                font-weight: 500;
                position: relative;
                margin: 24px 0 24px 12px;

                &::before {
                    content: '';
                    position: absolute;
                    left: -8px;
                    top: -1px;
                    width: 3px;
                    height: 20px;
                    background: #1890FF;
                }
            }
            .back {
                font-size: 14px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #333333;
                cursor: pointer;
            }
        }

        /*筛选*/

        .filter-view {
            box-sizing: border-box;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            padding: 0 24px;
            margin-top: 12px;

            .header-new-box {
                display: flex;
                align-items: center;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                white-space: nowrap;
                margin-right: 24px;
                margin-bottom: 12px;

                &-title {
                    margin-right: 16px;
                    white-space: nowrap;
                }
                .query-button  {
                    width: 84px;
                    height: 36px;
                    background: #FFFFFF;
                    border-radius: 4px;
                    border: 1px solid #1890FF;
                    font-size: 14px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #1890FF;
                    margin-right: 12px;
                }
            }
        }

        // 表格
        .table-wrapper {
            padding: 0 24px;
            flex: 1;
            height: 0;
            .cell-title {
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #333333;
                margin-bottom: 12px;
                display: -webkit-box;
                -webkit-box-orient: vertical;
                overflow: hidden;
                -webkit-line-clamp: 2;
            }
            .cell-content {
                display: -webkit-box;
                -webkit-box-orient: vertical;
                overflow: hidden;
                -webkit-line-clamp: 3;
            }
            .cell-tips {
                color: #999;
            }
        }
        .data-table {
            ::-webkit-scrollbar {
                width: 6px;
                height: 6px;
            }
            // 操作按钮
            .option-btn-group {
                .el-button {
                    margin-left: 0;
                    margin-right: 10px;
                }
            }
        }
        .status-wrapper {
            display: flex;
            align-items: center;
            justify-content: center;

            .status-dot {
                width: 6px;
                height: 6px;
                border-radius: 50%;
                margin-right: 5px;

                &.success {
                    background: #4CD964;
                }

                &.danger {
                    background: #FF3030;
                }

                &.warning {
                    background: #FFA72D;
                }

                &.normal {
                    background: #A6A6A6;
                }
            }
        }

        /* 分页 */
        .pagination-wrapper {
            padding: 12px 24px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    /deep/ .el-dialog__body {
        padding: 0;
    }
    /deep/ .el-textarea__inner {
        resize: none;
    }
    /deep/ .el-table__fixed-right {
        right: 6px!important;
    }
}
</style>
